package com.pearl.jacksoncore.demo.databind.anno;

import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder;

/**
 * @author TD
 * @version 1.0
 * @date 2024/3/28
 */
@JsonDeserialize(builder = Dog.Builder.class)
public class Dog {

    private final String name;
    private final Integer age;

    public String getName() {
        return name;
    }

    public Integer getAge() {
        return age;
    }

    @Override
    public String toString() {
        return "Dog{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    private Dog(String name, Integer age) {
        this.name = name;
        this.age = age;
    }
    @JsonPOJOBuilder
    static class Builder {
        String name;
        Integer age;

        Builder withName(String name) {
            this.name = name;
            return this;
        }

        Builder withAge(Integer age) {
            this.age = age;
            return this;
        }

        public Dog build() {
            System.out.println("使用build构建");
            return new Dog(name, age);
        }
    }
}
